package au.com.handsunited.model;

import org.hibernate.search.annotations.Indexed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.userdetails.UserDetails;

import au.com.handsunited.jodawrapper.JodaLocalDateWrapper;

/**
 * @author arunda
 *
 */
@Indexed
public class User extends BaseEntity implements UserDetails {

	private String firstName;
	private String lastName;
	private String username;
	private String password;
	private JodaLocalDateWrapper dateOfBirth;
	private String sex;

	private static Logger logger = LoggerFactory.getLogger(User.class);


	/**
	 *
	 */
	public User() {
		super();
		dateOfBirth = new JodaLocalDateWrapper();
	}

	/**
	 * @see au.com.handsunited.model.BaseEntity#isUser()
	 */
	@Override
	public boolean isUser() {
		return true;
	}

	public JodaLocalDateWrapper getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(JodaLocalDateWrapper dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getFullName() {
		return firstName + " " + lastName;
	}

	@Override
	public String getName() {
		return getFullName();
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getUsername() {
		return username;
	}

	/**
	 * @see au.com.handsunited.model.User#setUsername(java.lang.String)
	 */
	public void setUsername(String username) {
		this.username = username;
		getContactInfo().setEmailAddress(username);
	}

	/**
	 * @see au.com.handsunited.model.BaseEntity#getEntityType()
	 */
	@Override
	public String getEntityType() {
		return "user";
	}

	/**
	 * @see org.springframework.security.userdetails.UserDetails#getAuthorities()
	 */
	@Override
	public GrantedAuthority[] getAuthorities() {
		return null;
	}

	/**
	 * @see org.springframework.security.userdetails.UserDetails#isAccountNonExpired()
	 */
	@Override
	public boolean isAccountNonExpired() {
		return active;
	}

	/**
	 * @see org.springframework.security.userdetails.UserDetails#isAccountNonLocked()
	 */
	@Override
	public boolean isAccountNonLocked() {
		return active;
	}

	/**
	 * @see org.springframework.security.userdetails.UserDetails#isCredentialsNonExpired()
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * @see org.springframework.security.userdetails.UserDetails#isEnabled()
	 */
	@Override
	public boolean isEnabled() {
		return active;
	}




}
